package com.crm.web.admin;

import com.crm.VO.LineChartVO;
import com.crm.VO.PieChartVO;
import com.crm.VO.VulnerabilityMapVo;
import com.crm.result.Result;
import com.crm.service.ReportService;
import java.time.LocalDate;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping({"/report"})
@CrossOrigin
public class ReportController {
    @Autowired
    private ReportService reportService;

    public ReportController() {
    }

    @GetMapping({"/subjectStatistics/{beginCreateTime}/{endCreateTime}"})
    public Result subjectStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        List<PieChartVO> list = this.reportService.subjectStatistics(beginCreateTime, endCreateTime);
        return Result.success(list);
    }

    @GetMapping({"/cluesStatistics/{beginCreateTime}/{endCreateTime}"})
    public Result cluesStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        LineChartVO lineChartVO = this.reportService.cluesStatistics(beginCreateTime, endCreateTime);
        return Result.success(lineChartVO);
    }

    @GetMapping({"/salesStatistics/{beginCreateTime}/{endCreateTime}"})
    public Result salesStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        LineChartVO lineChartVO = this.reportService.salesStatistics(beginCreateTime, endCreateTime);
        return Result.success(lineChartVO);
    }

    @GetMapping({"/contractStatistics/{beginCreateTime}/{endCreateTime}"})
    public Result contractStatistics(@PathVariable("beginCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable("endCreateTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        LineChartVO lineChartVO = this.reportService.contractStatistics(beginCreateTime, endCreateTime);
        return Result.success(lineChartVO);
    }
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public Result getVulnerabilityMap(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime){
        VulnerabilityMapVo vulnerabilityMapVo=reportService.getVulnerabilityMap(beginCreateTime,endCreateTime);
        return Result.success(vulnerabilityMapVo);
    }
}